package com.demo2;

import com.demo2.bean.LicenseInfo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

// ========== 7. License生成工具使用示例 ==========
public class LicenseGenerationDemo {
    public static void main(String[] args) {
        try {
            System.out.println("=== License生成演示 ===");
            
            // 1. 首先需要运行KeyGenerator生成密钥对
            // 2. 然后使用私钥文件创建License生成器
            LicenseGenerator generator = new LicenseGenerator("private_key.pem");
            
            // 3. 创建license信息
            String customerName = "ABC科技有限公司";
            String productName = "SuperApp";
            String productVersion = "3.1.2";
            String expiryDate = LocalDateTime.now().plusYears(1).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
            String machineId = "WIN_12345-ABCDE-67890"; // 可以设置为"ANY"表示不限制机器
            int maxUsers = 100;
            
            LicenseInfo license = new LicenseInfo(customerName, productName, productVersion,
                                                 expiryDate, machineId, maxUsers);
            
            // 4. 添加功能特性
            license.addFeature("advancedReporting", true);
            license.addFeature("apiAccess", true);
            license.addFeature("cloudSync", false);
            license.addFeature("maxProjects", 50);
            
            // 5. 生成license文件
            String outputFile = customerName.replaceAll("[^a-zA-Z0-9]", "_") + "_license.lic";
            generator.generateLicense(license, outputFile);
            
            System.out.println("\n=== 操作完成 ===");
            System.out.println("请将 " + outputFile + " 文件发送给客户");
            
        } catch (Exception e) {
            System.err.println("License生成失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}